#include "thread.h"
#include <assert.h>


Thread::Thread()
{
    m_thread_id = 0;
    m_status = Thread::READY;
}

void Thread::start()
{
    if (m_status != Thread::READY)
        return;

    pthread_create(&m_thread_id, NULL, ThreadProcess, this);
}

void Thread::exit(void* ret_val)
{
    pthread_exit(&ret_val);
    m_status = Thread::EXIT;
}

void* ThreadProcess(void* thread)
{
    assert(thread != NULL);
    Thread* my_thread = (Thread*) thread;
    my_thread->setStatus(Thread::RUNNING);
    my_thread->run();
    my_thread->setStatus(Thread::EXIT);
    return NULL;
}



